package com.example.learn.hwod;

import java.util.Arrays;
import java.util.Scanner;

public class _03靠谱的车 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] array = Arrays.stream(sc.nextLine().split("")).mapToInt(Integer::parseInt).toArray();
        System.out.println(getResult(array));

    }

    private static int getResult(int[] array) {
        int price=0;
        for(int i =0;i<array.length;i++){
            int number = array[i];
            if (number>4) {
                number--;
            }
            for(int j =array.length-i-1;j>0;j--){
                number*=9;
            }
            price+=number;
        }
        return price;

    }
}
